import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { HttpRequest } from "../../../../service/httpRequest";
import { PageModel } from "../../../../model/page-model";

@Component({
  selector: 'app-monitor-deviceonline',
  templateUrl: './device-online.component.html',
  styleUrls: ['./device-online.component.css']
})
export class DeviceonlinesComponent implements OnInit {
  
  constructor(private activeRoute:ActivatedRoute,private httpRequest:HttpRequest) { }
  devinfoData:any;
  deviceId:any;
  devstatusdata:any;
  pageModel = new PageModel();
  page:number = 1;
  ngOnInit() {
  	this.activeRoute.params.subscribe(
      params=>{
        this.deviceId = params['deviceId'];      
       	this.getdevinfo();
       	this.getstatusdata();
      })
   }

    getdevinfo(){
	    this.httpRequest.sendGet('devices',{id:this.deviceId}).subscribe(res => {  
	      //console.log(res)    
	      this.devinfoData = res.result;    
	      //console.log(this.devinfoData)  
	    },err => console.log(err));
  	}

  	getstatusdata(){
  		this.httpRequest.sendGet('devices/onlines',{id:this.deviceId,page:this.page}).subscribe(res => {  
	      //console.log(res)   
	      if(res.resultStatus==200){
	      	this.devstatusdata = res.result;
	      	this.pageModel.setPage({'iTotalRecords':res.total_amount});
	      } 	    
	    },err => console.log(err));
  	}



}